<template>
  <div class="warning-record-action flex flex-column">
    <a-radio-group
      v-model:value="activeType"
      :options="dataList"
      @change="radioChange"
      option-type="button"
      class="flex-fixed"
      style="margin-bottom: 10px"
    />
    <common-table
      ref="table"
      :fetch-params="paramsData"
      :fetch="getDataAsync"
      :columns="resultColumns"
      :show-toolbar="false"
      @vue:mounted="() => $refs.table.load()"
      class="flex-auto-height"
    >
      <template #action="{ text, scope }">
        <span v-if="activeType == '1'" style="color: #62b8b1; cursor: pointer" @click="warningHandle(scope)"
          >预警处理</span
        >
        <!--        <span v-else style="color: #62b8b1; cursor: pointer" @click="warningHandleNote(scope)">处罚备注</span>-->
      </template>
    </common-table>
  </div>
</template>

<script>
import { dialog } from '@gis/lib/components/antd-dialog';
import { alarmPageList, homestayWarningPointList } from '@gis/lib/api';
import { handleTableRes } from '@gis/lib/utils/resolver.js';
import { getEnumText } from '@gis/lib/enums/index.js';
import { openAlarmHandleDialog } from '../../../alarm/alarm-handle.js';

export default {
  name: 'warning-record-action-old',
  props: {
    details: { type: Object, default: () => {} },
  },
  data() {
    return {
      dataList: [
        { label: '未处理', value: '1' },
        { label: '已处理', value: '2' },
      ],
      activeType: '1',
      columns: [
        {
          title: '预警类型',
          dataIndex: 'warn_type_name',
        },
        {
          title: '预警时间',
          dataIndex: 'gmt_modified',
        },
        {
          title: '预警描述',
          dataIndex: 'reason',
        },
        {
          title: '处理状态',
          dataIndex: 'is_handle',
          customRender: (val) => getEnumText('handleStatus', val),
        },
        {
          title: '处理时间',
          dataIndex: 'handle_time',
        },
        {
          title: '处理结果',
          dataIndex: 'handle_result',
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          align: 'center',
          width: 100,
        },
      ],
    };
  },
  computed: {
    resultColumns() {
      if (this.activeType == '1') {
        return [0, 1, 2, 3, 4, 7].reduce((res, i) => res.concat(this.columns.slice(i, i + 1)), []);
      } else {
        return [].concat(this.columns);
      }
    },
    paramsData() {
      return Object.assign(
        {},
        {
          // handle_status: this.activeType,
          // warn_category_code: 'D0142_3',
          // warn_type_code: 'D0142_3_2,D0142_3_3,D0142_3_4',
          // field1: this.details.hotel_id, //酒店值
          // yard_id: this.details.yard_id,

          is_handle: this.activeType,
          hotel_id: this.details.hotel_id,
          warn_type_str: '2,3,4',
        }
      );
    },
  },
  methods: {
    // warningHandleNote(scope) {
    //   dialog({
    //     content: () => import('@/views/homestay-warning/components/point-detail/warning-handle-note.vue'),
    //     contentProps: {
    //       id: scope.id,
    //       content: scope.punishment_result,
    //     },
    //     contentEvents: {
    //       handleSuccess: () => {
    //         this.$refs.table.refresh();
    //       },
    //     },
    //     dialogProps: {
    //       title: '预警处罚结果',
    //       footer: null,
    //     },
    //   });
    // },
    warningHandle(scope) {
      openAlarmHandleDialog(scope).then((res) => {
        if (res) this.$refs.table.load();
      });
    },
    radioChange() {
      this.$nextTick(() => {
        this.$refs.table.load();
      });
    },
    async getDataAsync(params) {
      // if (!params.warn_type_code) return;
      return await handleTableRes(homestayWarningPointList(params));
    },
  },
};
</script>

<style scoped lang="less">
.warning-record-action {
  width: 100%;
  height: 100%;
}
</style>
